This invention relates generally to intermediate languages, and more particularly to compiling and persisting of intermediate language code.
Intermediate language-type models for programming languages have become increasingly popular. In an intermediate language model, a source code is generally compiled into a desirably substantially platform-independent intermediate language. When the code is desired to be run on a particular platform, an execution engine on that platform then interprets or compiles the intermediate language to native code understandable by the platform. Examples of systems that use intermediate languages include the Java virtual machine.
As used herein, the terminology intermediate language refers generally to an intermediate language format that is an executable format and that is designed to be run. It can be loaded with very little time and memory overhead. Each part of such a format is typically designed to allow execution with minimal effort; all information required to execute part of the code is present. Such intermediate languages include byte code as used by Java virtual machines, for example. The terminology intermediate language as used herein does not generally refer to the data communicated from the front end of a compilerxe2x80x94for example, a typical C compilerxe2x80x94to the back end of the compiler.
Interpretation of intermediate language code means that as each individual instruction of intermediate language code is encountered, it is decoded and executed. Interpretation is usually the slowest manner by which intermediate language code can be executed. Therefore, compilation of intermediate language code to native code is generally used over interpretation of the intermediate code.
With respect to intermediate language code, compilation to native code is conducted within the prior art on adjust-in-time basis, such that the process is often referred to as just-in-time compilation. Just-in-time compilation of intermediate language code to native code means that a section of intermediate language code instructions is examined and converted to a corresponding section of native code, which is then executed. Thus, as compared to interpretation, which decodes and executes IL code on a instruction-by-instruction basis, just-in-time compilation converts and executes code on a section-by-section basis.
Generally, just-in-time compilation results in faster execution than does interpretation. However, there are disadvantages to the just-in-time compilation approach. Each time a program is run, it must be reconverted to native code. Because conversion time is at a premium, just-in-time compilation often sacrifices the quality of the native code for compilation speed, resulting in native code that may be worse in quality than that generated by a traditional source code-to-native code compiler. The native code that is generated also is tailored specifically to the individual program running; multiple programs cannot usually share native code. In addition, since two versions of the program, an intermediate language version and a native version, are loaded into memory, the resource requirements of a just-in-time compiled program are generally undesirably large.
Furthermore, while just-in-time compilation results in faster execution than does interpretation, just-in-time compilation of intermediate language code to native code still typically results in much slower execution than does straight execution of native code that was compiled directly from source code. Generally, this trade-off is taken for granted as an inherent characteristic of intermediate-language code: what is gained in platform independence is lost in execution speed. Nevertheless, it is desirable for intermediate-language code to be executed as fast as possible. For these and other reasons, there is a need for the present invention.
The invention relates to compilation and persisting of intermediate language code, as this phrase has been defined in the background section. In one embodiment, a computer-implemented method first inputs intermediate language code. The method compiles this code into corresponding native codexe2x80x94for example, in a non-just-in-time manner. The method then outputs the native codexe2x80x94for example, persisting the native code to a hard disk drive or a non-volatile memory. Only then is the native code executed. In one embodiment, verifiability is provided for.
Embodiments of the invention hence differ in their approach to compilation of intermediate language code as compared to the prior art. Usually all of the intermediate language code is compiled to native code prior to the native code being executed. This means that the native code can be saved to a hard disk drive, for example, and then later executed, without the performance penalties typically associated with intermediate language code. The initial compilation of the intermediate language code into native code can be performed as a program installation-type procedure that computer users are typically accustomed to with more traditional programs compiled directly to native code from source code, or, the initial compilation can be performed in the background, while the user is doing other things.
Within embodiments of the invention, generally the conversion from intermediate language code to native code occurs on the target machine on which the native code is meant to be run. This conversion is desirably made by an optimizing compiler, which is managed within the run-time environment. The goal of the conversion is generally to preserve the benefits of intermediate language code distributionxe2x80x94such as verifiability, platform independence, and late bindingxe2x80x94while achieving the performance advantage of an optimizing compiler, and not incurring run-time performance penalties.
While the prior art provides for interpretation of intermediate language code on an instruction-by-instruction basis and for just-in-time compilation of intermediate language code on a section-by-section basis, embodiments of the invention provide for complete whole-program compilation prior to execution. Execution of the resulting native code is therefore usually faster than the execution of just-in-time compiled code, and in some instances approaches that of more traditional programs compiled directly to native code from source code. Embodiments of the invention thus provide to large degree the best of both worlds: the speed of execution of more traditional programs, and the platform portability (i.e., independence) of intermediate language programs.
The invention includes computer-implemented methods, machine-readable media, computerized systems, devices and computers of varying scopes. Other aspects, embodiments and advantages of the invention, beyond those described here, will become apparent by reading the detailed description and with reference to the drawings.